<?php
@session_start();
require_once '../sub/init.php';
require_once ZEAI.'sub/conn.php';
if (!is_mobile())exit('请用手机打开');
require_once ZEAI.'cache/config_reg.php';
require_once ZEAI.'sub/www_zeai_cn_sms.php';
require_once ZEAI.'sub/zeai_up_func.php';
require_once ZEAI.'cache/config_shop.php';
$TG_set = json_decode(stripslashes($_REG['TG_set']),true);
if(@!in_array('tg',$navarr))exit("<div style='font-size:30px;text-align:center;margin:50px'>推广功能暂未开启</div>");
$jumpurl = trimhtml(dataIO($jumpurl,'out'));
$ip=getip();
if (is_weixin()){
	if(str_len($cook_tg_openid)>20){
		$server_tg_openid = $cook_tg_openid;
	}else{
		$server_tg_openid = wx_get_openid(0);
		setcookie("cook_tg_openid",$server_tg_openid,time()+31536000,"/",$_ZEAI['CookDomain']);
	}
}
switch ($submitok) {
	case 'tg_login_forgetpass_update':
		if (!ifmob($mob))json_exit(array('flag'=>0,'msg'=>'请输入正确的手机号码'));
		if (str_len($newpass) > 20 || str_len($newpass) < 6)json_exit(array('flag'=>0,'msg'=>'新密码长度请控制在6~20长度'));
		$row = $db->ROW(__TBL_TG_USER__,'id',"mob='".$mob."' AND FIND_IN_SET('mob',RZ) ");
		if(!$row)json_exit(array('flag'=>0,'msg'=>'此手机号码未注册或未认证,请重新输入'));
		//验证码处理
		$verify = intval($verify);
		if (empty($_SESSION['Zeai_cn__verify'])){
			json_exit(array('flag'=>0,'msg'=>'短信验证码错误，请重新获取'));
		}else{
			if ($_SESSION['Zeai_cn__verify'] != $verify){
				json_exit(array('flag'=>0,'msg'=>'短信验证码不正确'));
			}
			if ($_SESSION['Zeai_cn__mob'] != $mob && ifmob($mob)){
				unset($_SESSION["Zeai_cn__verify"]);
				unset($_SESSION["Zeai_cn__mob"]);
				json_exit(array('flag'=>0,'msg'=>'手机号码异常，请重新获取'));
			}
		}
		$db->query("UPDATE ".__TBL_TG_USER__." SET pwd='".md5($newpass)."' WHERE mob='$mob'");
		json_exit(array('flag'=>1,'msg'=>$msg,'newpass'=>$newpass));	
	break;
	case 'ajax_click_yzm':
		$yzmarr = array('壹'=>'1','贰'=>'2','叁'=>'3','肆'=>'4','伍'=>'5','陆'=>'6','柒'=>'7','捌'=>'8','玖'=>'9','零'=>'0');
		$_SESSION['colorKey'] = array_rand($yzmarr,1);
		$_SESSION['colorV']   = $yzmarr[$_SESSION['colorKey']];
		$yzmarr_new=shuffle_arr($yzmarr);
		foreach ($yzmarr_new as $k=>$V) {$echo.= '<li class=breath>'.$V.'</li>';}
		json_exit(array('flag'=>1,'key'=>$_SESSION['colorKey'],'li'=>$echo));	
	break;
	case 'ajax_click_yzm_chk':
		if($v==$_SESSION['colorV'] && $key==$_SESSION['colorKey']){
			json_exit(array('flag'=>1,'msg'=>'好样的，选择正确，正在发送手机验证码'));
		}else{
			json_exit(array('flag'=>0,'msg'=>'选择错误，请重新选择'));
		}
	break;
	case 'ajax_reg_verify':
		if ($TG_set['regkind'] == 2)exit(JSON_ERROR);
		if(  $v!=$_SESSION['colorV'] || $key!=$_SESSION['colorKey']  ){json_exit(array('flag'=>0,'msg'=>'选择错误，请重新选择获取！'));}
		unset($_SESSION["colorKey"]);
		unset($_SESSION["colorV"]);
		if(!ifmob($mob))json_exit(array('flag'=>0,'msg'=>'请输入正确的手机号码'));
		if (($Temp_regyzmrenum > $_SMS['sms_yzmnum']) && $_SMS['sms_yzmnum']>0  )json_exit(array('flag'=>0,'msg'=>'你重复发送次数过多，已暂停发送'));
		$_SESSION['Zeai_cn__verify'] = cdstr(4);
		//sms
		$rtn = Zeai_sendsms_authcode($mob,$_SESSION['Zeai_cn__verify']);
		$rtn=0;
		if ($rtn == 0){
			setcookie("Temp_regyzmrenum",$Temp_regyzmrenum+1,time()+31536000,"/",$_ZEAI['CookDomain']);  
			$chkflag = 1;
			$content = '验证码发送成功，请注意查收';//.$_SESSION['Zeai_cn__verify']
		}else{
			$chkflag = 0;
			$content = "发送失败,错误码：$rtn"."-".sms_error($rtn);
		}
		//sms end
		$_SESSION['Zeai_cn__mob'] = $mob;
		json_exit(array('flag'=>$chkflag,'msg'=>$content));
	break;
	case 'ajax_uname_addupdate':
		if ($TG_set['regkind'] == 2){
			$uname = dataIO(trimhtml($uname),'in',20);
			$pwd   = trimhtml($pwd);
			if (str_len($pwd) > 20 || str_len($pwd) < 6)json_exit(array('flag'=>0,'msg'=>'密码长度请控制在6~20长度'));
			$pwd   = md5($pwd);
			if (ifint($uname,'0-9','1,8')){
				chk_flag1Fn("id='".$uname."'",2);
			}elseif(ifmob($uname)){
				chk_flag1Fn("mob='$uname' AND FIND_IN_SET('mob',RZ) ",2);
			}else{
				if (str_len($uname) > 20 || str_len($uname) < 3)json_exit(array('flag'=>0,'msg'=>'请输入正确的登录帐号（3~20位字母或加数字组合）'));
				if (ifmob($uname) || ifint($uname))json_exit(array('flag'=>0,'msg'=>'登录用户名不能是手机号码和纯数字'));
				if (!preg_match('/^[A-Za-z0-9_\x{4e00}-\x{9fa5}]+$/u',$uname) )json_exit(array('flag'=>0,'msg'=>'请输入正确的用户名（3~15位字母或加数字组合）'));
				chk_flag1Fn("uname='".$uname."'",2);
			}
			$SQL .= "uname='$uname'";
		}else{
			if (!ifmob($mob))json_exit(array('flag'=>0,'msg'=>'请输入正确的手机号码'));
			if (empty($_SESSION['Zeai_cn__verify'])){
				json_exit(array('flag'=>0,'msg'=>'短信验证码错误，请重新获取'));
			}else{
				if ($_SESSION['Zeai_cn__verify'] != $verify)json_exit(array('flag'=>0,'msg'=>'您填的短信验证码不正确'));
				if ($_SESSION['Zeai_cn__mob'] != $mob){
					unset($_SESSION["Zeai_cn__mob"]);
					json_exit(array('flag'=>0,'msg'=>'手机号码异常，请重新获取'));
				}
			}
			chk_flag1Fn("mob='".$mob."' AND FIND_IN_SET('mob',RZ) ");
			$SQL .= "mob='$mob',RZ='mob'";
			$pwd  = md5(cdnumletters(6));
		}
		/**************** 入库 ******************/
		$flag = ($TG_set['regflag'] == 1)?0:1;
		$flag = ($TG_set['active_price'] >0)?2:$flag;//需要交费
		//
		$row    = $db->ROW(__TBL_TG_ROLE__,"grade,title","shopgrade=0 AND ifdefault=1","num");
		$grade  = $row[0];$gradetitle = $row[1];
		$SQL   .= ",grade=".$grade.",gradetitle='$gradetitle',sjtime='".ADDTIME."'";
		//
		$tguid  = intval($tguid);
		$subscribe = intval($subscribe);
		$db->query("INSERT INTO ".__TBL_TG_USER__." (subscribe,pwd,regtime,endtime,regip,endip,openid,tguid,flag) VALUES ($subscribe,'".$pwd."',".ADDTIME.",".ADDTIME.",'$ip','$ip','$server_tg_openid',$tguid,$flag)");
		$tg_uid = intval($db->insert_id());
		
		if ($TG_set['regkind'] == 1){
			$uname = 'tg_'.$tg_uid;
		}
		//微信openid查获主会员表有，复制资料
		if (is_weixin() && !empty($server_tg_openid)){
			$rowu = $db->ROW(__TBL_USER__,"id,uname,subscribe,nickname,photo_s,tguid","openid='$server_tg_openid' AND openid<>'' ","name");
			if ($rowu){
				$uid       = intval($rowu['id']);
				if ($TG_set['regkind'] == 1)$uname = $rowu['uname'];
				$subscribe = intval($rowu['subscribe']);
				$nickname  = $rowu['nickname'];
				$photo_s   = $rowu['photo_s'];
				$tguid_     = $rowu['tguid'];
				$SQL .= ",uid=".$uid;
				if($subscribe==1)$SQL   .= ",subscribe=1";
				if(!ifint($tguid) )$SQL .= ",tguid='$tguid_'";
				if(!empty($photo_s)){
					$new_photo_s=str_replace("/m/","/tg/",$photo_s);
					UP_modFn('guest','copy',$photo_s,str_replace("/m/","/tg/",$photo_s));
					UP_modFn('guest','copy',smb($photo_s,'m'),str_replace("/m/","/tg/",smb($photo_s,'m')));
					UP_modFn('guest','copy',smb($photo_s,'b'),str_replace("/m/","/tg/",smb($photo_s,'b')));
					$photo_s=$new_photo_s;
				}
			}else{
				$server_token = wx_get_access_token();
				$wxuinfo  = wx_get_uinfo($server_token,$server_tg_openid);
				$nickname = trimmhtml(dataIO($wxuinfo['nickname'],'in',100));
				$subscribe= ($wxuinfo['subscribe']==1)?1:0;
				$dbname = (!empty($wxuinfo['headimgurl']))?wx_get_uinfo_logo($wxuinfo['headimgurl'],$tg_uid):'';
				$photo_s= setpath_s($dbname);
			}
			$SQL .= ",subscribe=".$subscribe.",nickname='".$nickname."',photo_s='".$photo_s."'";
		}
		$db->query("UPDATE ".__TBL_TG_USER__." SET ".$SQL." WHERE id=".$tg_uid);
		setcookie("cook_tg_uid",$tg_uid,time()+31536000,"/",$_ZEAI['CookDomain']);
		setcookie("cook_tg_pwd",$pwd,time()+31536000,"/",$_ZEAI['CookDomain']);
		if ($TG_set['regkind'] == 1){
			unset($_SESSION["Zeai_cn__verify"]);
			unset($_SESSION["Zeai_cn__mob"]);
		}
		if(ifint($tguid))TG($tguid,$tg_uid,'tg_reg');
		$jumpurl=(!empty($jumpurl))?$jumpurl:'tg_reg.php?submitok=success&loginkind='.$loginkind;
		json_exit(array('flag'=>1,'msg'=>'登录成功','jumpurl'=>$jumpurl));
	break;
}
//自动登录
if(ifint($cook_tg_uid) && !empty($cook_tg_pwd)){
	$rowtg = $db->ROW(__TBL_TG_USER__,"id,uname,pwd","id=".$cook_tg_uid." AND pwd='$cook_tg_pwd'","name");
	if ($rowtg){
		if($loginkind=='shop'){
			$jumpurl=(!empty($jumpurl))?$jumpurl:'shop_my.php';
			header("Location: ".$jumpurl);
		}else{
			header("Location: tg_my.php");
		}
		exit;
	}
}else{
	if(ifint($cook_uid) && !empty($cook_pwd)){
		$rowU = $db->ROW(__TBL_USER__,"uname,pwd,nickname,mob,RZ,openid,subscribe,weixin,qq,aboutus,areaid,areatitle,photo_s,tguid","id=".$cook_uid." AND pwd='$cook_pwd'");
		if($rowU){
			$rowtg = $db->ROW(__TBL_TG_USER__,"id,uname,pwd","uid=".$cook_uid,"name");
			if ($rowtg){
				$cook_tg_uid   = $rowtg['id'];
				$cook_tg_pwd   = $rowtg['pwd'];
				setcookie("cook_tg_uid",$cook_tg_uid,time()+31536000,"/",$_ZEAI['CookDomain']);
				setcookie("cook_tg_pwd",$cook_tg_pwd,time()+31536000,"/",$_ZEAI['CookDomain']);
				if($loginkind=='shop'){
					$jumpurl=(!empty($jumpurl))?$jumpurl:'shop_my.php';
					header("Location: ".$jumpurl);
				}else{
					header("Location: tg_my.php");
				}
				exit;
			}else{
				//新增
				$mob= $rowU['mob'];
				$uname=$rowU['uname'];
				$pwd  = $rowU['pwd'];
				$openid    =$rowU['openid'];
				$subscribe =$rowU['subscribe'];
				$RZ      = $rowU['RZ'];$RZarr = explode(',',$RZ);
				$weixin  = $rowU['weixin'];
				$qq      = $rowU['qq'];
				$aboutus = $rowU['aboutus'];
				$areaid  = $rowU['areaid'];
				$areatitle = $rowU['areatitle'];
				$nickname  = $rowU['nickname'];
				$photo_s   = $rowU['photo_s'];
				$U_tguid   = intval($rowU['tguid']);
				if(ifmob($mob) && in_array('mob',$RZarr)){
					$rowtg2 = $db->ROW(__TBL_TG_USER__,"id,uname,mob,pwd","mob='$mob' AND FIND_IN_SET('mob',RZ)","name");
					if($rowtg2){
						$cook_tg_uid   = $rowtg2['id'];
						$cook_tg_uname = $rowtg2['uname'];
						$cook_tg_mob   = $rowtg2['mob'];
						$cook_tg_pwd   = $rowtg2['pwd'];
						setcookie("cook_tg_uid",$cook_tg_uid,time()+31536000,"/",$_ZEAI['CookDomain']);
						setcookie("cook_tg_pwd",$cook_tg_pwd,time()+31536000,"/",$_ZEAI['CookDomain']);
					}else{
						$ifadd=true;
					}
				}else{
					$ifadd=true;
				}
				//
				if($ifadd){
					$ip     =getip();
					$row2 = $db->ROW(__TBL_TG_USER__,"id","uname='$uname'");
					if($row2)$uname=$cook_uid;
					//
					if(!empty($photo_s)){
						$new_photo_s=str_replace("/m/","/tg/",$photo_s);
						UP_modFn('guest','copy',$photo_s,$new_photo_s);
						UP_modFn('guest','copy',smb($photo_s,'b'),str_replace("/m/","/tg/",smb($photo_s,'b')));
						UP_modFn('guest','copy',smb($photo_s,'m'),str_replace("/m/","/tg/",smb($photo_s,'m')));
					}
					//
					$flag = ($TG_set['regflag'] == 1)?0:1;
					$flag = ($TG_set['active_price'] >0)?2:$flag;//需要交费
					$row    = $db->ROW(__TBL_TG_ROLE__,"grade,title","shopgrade=0 AND ifdefault=1","num");
					$grade  = $row[0];$gradetitle = $row[1];
					$SQL   .= "grade=".$grade.",gradetitle='$gradetitle',sjtime='".ADDTIME."'";
					//
					$db->query("INSERT INTO ".__TBL_TG_USER__." (tguid,uid,uname,nickname,pwd,regtime,endtime,regip,endip,openid,subscribe,qq,weixin,content,areaid,areatitle,photo_s,flag) VALUES ($U_tguid,$cook_uid,'$uname','$nickname','".$pwd."',".ADDTIME.",".ADDTIME.",'$ip','$ip','$openid','$subscribe','$qq','$weixin','$aboutus','$areaid','$areatitle','$new_photo_s','$flag')");
					$cook_tg_uid = intval($db->insert_id());
					if(ifmob($mob) && in_array('mob',$RZarr)){
						$SQL .= ",mob='$mob',RZ='mob'";
					}
					$db->query("UPDATE ".__TBL_TG_USER__." SET ".$SQL." WHERE id=".$cook_tg_uid);
					$cook_tg_pwd = $pwd;
					$cook_tg_openid= $openid;
					setcookie("cook_tg_uid",$cook_tg_uid,time()+31536000,"/",$_ZEAI['CookDomain']);
					setcookie("cook_tg_pwd",$cook_tg_pwd,time()+31536000,"/",$_ZEAI['CookDomain']);
					setcookie("cook_tg_openid",$cook_tg_openid,time()+7200000,"/",$_ZEAI['CookDomain']);
					if($loginkind=='shop'){
						$jumpurl=(!empty($jumpurl))?$jumpurl:'shop_my.php';
						header("Location: ".$jumpurl);
					}else{
						header("Location: tg_my.php");
					}
				}
			}
		}
	}
}
if (is_weixin()){
	//微信自动进入
	$row = $db->ROW(__TBL_TG_USER__,"id,uname,flag,mob,pwd","openid<>'' AND openid='".$server_tg_openid."'","num");
	if ($row){
		$tg_uid = $row[0];$tg_uname = $row[1];$flag = $row[2];$tg_mob = $row[3];$tg_pwd = $row[4];
		if ($flag==-1)alert('您的帐号已被锁定','back');
		setcookie("cook_tg_uid",$tg_uid,time()+31536000,"/",$_ZEAI['CookDomain']);
		setcookie("cook_tg_pwd",$tg_pwd,time()+31536000,"/",$_ZEAI['CookDomain']);
		if($loginkind=='shop'){
			$jumpurl=(!empty($jumpurl))?$jumpurl:HOST.'/m/shop_my.php';
			header("Location: ".$jumpurl);
		}else{
			header("Location: tg_my.php");
		}
		exit;
	}
}

/*if($loginkind=='shop'){
	$h1title = $_SHOP['title'];
}else{
	$h1title = $TG_set['tgytitle'];
}*/
$h1title='推广/商城';
$headertitle = $h1title.'登录-';
$nav = '';require_once ZEAI.'m/header.php';
?>
<link href="<?php echo RES;?>m/css/tg_loginreg.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<link href="<?php echo HOST;?>/cache/zeaicolor.css?<?php echo $_ZEAI['cache_str'];?>" rel="stylesheet" type="text/css" />
<?php 
$mini_class = 'top_mini4';
require_once ZEAI.'m/top_mini.php';
?>
<div class="tglogin" id="main">
    <h1>登录注册更精彩</h1>
    <h5>登录注册表示同意 <a id="clause">《用户协议、隐私条款》</a></h5>
    <div class="box">
        <form id="WWW_ZEAI_CN_form">
        <?php if ($TG_set['regkind'] == 1){?>
            <dl><dt><i class="ico">&#xe627;</i></dt><dd><input required name="mob" type="text" id="mob" placeholder="请输入手机号码" autocomplete="off" maxlength="11" pattern="[0-9]*" onBlur="zeai.setScrollTop(0);"></dd></dl>
            <dl><dt><i class="ico">&#xe6c3;</i></dt><dd class="yzmF">
            <input name="verify" id="verify" type="text" required maxlength="4" placeholder="请输入验证码" autocomplete="off"  onBlur="zeai.setScrollTop(0);"  pattern="[0-9]*" /><a href="javascript:verifyFn(yzmbtn);" class="yzmbtn" id="yzmbtn">获取验证码</a>
            </dd></dl>
            <div id="zeai_yzm" class="divTopDown"><em id="zeai_yzm_em"></em><span>对应的小写是？点击下面数字确定</span><div class="text" id="zeai_yzm_li"></div></div>
        <?php }else{ ?>

            <dl><dt><i class="ico">&#xe645;</i></dt><dd><input name="uname" type="text" class="input_login" id="uname" placeholder="请输入ID/用户名/手机" autocomplete="off" maxlength="20" value="<?php echo $cook_admid;?>"></dd></dl>
            <dl><dt><i class="ico">&#xe620;</i></dt><dd><input name="pwd" type="password" class="input_login" id="pwd" placeholder="请输入登录密码" autocomplete="off" maxlength="20"></dd></dl>
            <div class="clear"></div>
            <div class="areg"><a id="forgetpass_btn">忘记密码？</a></div>
        <?php }?>
        <input type="hidden" name="loginkind" value="<?php echo trimhtml($loginkind);?>">
        <input type="hidden" name="jumpurl" value="<?php echo trimhtml(dataIO($jumpurl,'out'));?>">
        <input type="hidden" name="submitok" id="submitok" value="ajax_uname_addupdate">
        <button type="button" class="btn size4 zeaibg yuan" onClick="regbtnFn();">注册/登录</button>
        </form>
        <div class="clear"></div>
    </div>
</div>

<div id="clausebox">
    <i class='ico Ugoback' onclick="div_left_mask.click()">&#xe602;</i>
    <div class="title">用户协议、隐私条款</div>
	<div class="C"><?php echo dataIO($TG_set['clause'],'out');?></div>
</div>
<?php if ($TG_set['regkind'] == 2){?>
<div id="forgetpassbox" class="forgetpass" style="display:none">
    <div class="forgetpassbox">
        <form id="WWW__ZEAI_CN_form">
            <dl style="padding-top:0px;margin-top:0"><dt><i class="ico">&#xe627;</i></dt><dd><input name="mob" type="text" class="input_login" id="mob" placeholder="请输入手机号码" autocomplete="off" maxlength="11" pattern="[0-9]*" onBlur="zeai.setScrollTop(0);"></dd></dl>
            <dl><dt><i class="ico">&#xe6c3;</i></dt><dd class="yzmF">
            <input name="verify" id="verify" type="text" required class="input_login" maxlength="4" placeholder="输入短信验证码" autocomplete="off"  onBlur="zeai.setScrollTop(0);" /><a href="javascript:;" class="yzmbtn" id="yzmbtn">获取验证码</a>
            </dd></dl>
            <dl style="padding-top:0px;margin-top:0"><dt><i class="ico">&#xe620;</i></dt><dd><input name="newpass" type="text" class="input_login" id="newpass" placeholder="请输入新密码6~20长度" maxlength="20"></dd></dl>
            <button type="button" class="btn size4 zeaibg yuan" onClick="forgetpassFn();">修改密码</button>
        </form>
        <div class="ok" id="ok">
            <i class="ico flag">&#xe60f;</i>
            <h4 class="textok">密码重置成功，请牢记</h4>
            <h4 class="title"><span>您的新密码为：</span><b id="newpassstr"></b>　<a class="btn size1 BAI" onclick="zeai.copy(newpassstr.innerHTML,function(){zeai.msg('复制成功');})">复制密码</a></h4>
        </div>
    </div>
    <script>
        function forgetpassFn(){
            var mobV = o('mob').value,verifyV=o('verify').value,newpass=o('newpass').value;
            if(!zeai.ifmob(mobV)){zeai.msg('请输入正确手机号');return false;}
            if(!zeai.ifint(verifyV) || zeai.str_len(verifyV)!=4 ){zeai.msg('请输入【手机验证码】');return false;}
            if(zeai.str_len(newpass)>20 || zeai.str_len(newpass)<6){zeai.msg('请输入【新密码】6~20长度');return false;}
            zeai.ajax({url:'tg_login'+zeai.ajxext+'submitok=tg_login_forgetpass_update',form:WWW__ZEAI_CN_form},function(e){var rs=zeai.jsoneval(e);
                zeai.msg(0);zeai.msg(rs.msg);
                if(rs.flag==1){WWW__ZEAI_CN_form.hide();ok.show();newpassstr.html(rs.newpass);}
            });
        }
        zeai.verify({mob:mob,verify:verify,yzmbtn:yzmbtn,url:MHOST+'/tg_login.php?submitok=ajax_get_verify&kind=forgetpass_tg',sec:120});
    </script>    
</div>
<?php }?>
<script>
var url='tg_login',reg_kind=<?php echo intval($TG_set['regkind']);?>;
/*yzm*/
function verifyFn(yzmbtn){
	if (zeai.ifmob(o('mob').value)){
		if (!yzmbtn.hasClass('disabled')){ajax_click_yzmFn();}
	}else{
		zeai.msg('请输入手机号码');return false;
	}
}
function ajax_click_yzmFn(){
	zeai.ajax({url:url+zeai.ajxext+'submitok=ajax_click_yzm'},function(e){var rs=zeai.jsoneval(e);
		zeai_yzm_em.html(rs.key);
		zeai_yzm_li.html(rs.li);
		zeai.mask({son:zeai_yzm,maskcls:'mask_TRnav'});
		zeai.listEach(zeai.tag(zeai_yzm_li,'li'),function(obj){
			obj.onclick=function(){zeai_yzm_liFn(rs.key,this.innerHTML);};
		});

	});
}
function zeai_yzm_liFn(key,v){
	zeai.ajax({url:url+zeai.ajxext+'submitok=ajax_click_yzm_chk',data:{key:key,v:v}},function(e){var rs=zeai.jsoneval(e);
		zeai.msg(0);
		if(rs.flag==1){
			zeai_yzm.hide();
			setTimeout(function(){
				if (!yzmbtn.hasClass('disabled')){
					yzmbtn.addClass('disabled');
					zeai.ajax({url:url+zeai.extname,data:{'submitok':'ajax_reg_verify',mob:o('mob').value,key:key,v:v}},function(e){
						var rs=zeai.jsoneval(e);
						zeai.msg(0);
						if (rs.flag == 1){
							zeai.msg(rs.msg,{time:5});o('verify').value='';yzmtimeFn2(120);//120
						}else{
							zeai.msg(rs.msg);yzmbtn.removeClass('disabled');
						}
						Mzeai_yzm.click();
					});
				}
			},200);			
		}else{
			zeai.msg(rs.msg);
			setTimeout(function(){ajax_click_yzmFn();},1000);
		}
	});
}
function yzmtimeFn2(countdown){
	var yzmbtn=o('yzmbtn');
	if (countdown == 0) {
		yzmbtn.removeClass('disabled');yzmbtn.html('<font>重新获取</font>');return false;
	} else { 
		yzmbtn.addClass('disabled');yzmbtn.html("重新发送<b>"+countdown+"s</b>");countdown--; 
	} 
	cleandsj=setTimeout(function(){yzmtimeFn2(countdown)},1000);
}
function regbtnFn(){
	if(reg_kind==2){
		var unameV = o('uname').value;
		var pwdV   = o('pwd').value;
		if(zeai.str_len(unameV) < 1 || zeai.str_len(unameV)>15){zeai.msg('请输入登录用帐号(必须为3-15字符长度)',o('uname'));return false;}
		if(zeai.str_len(pwdV)<6 || zeai.str_len(pwdV)>20){zeai.msg('请输入登录密码(必须为6-20字符长度)',o('pwd'));return false;}
	}else{	
		var mobV = o('mob').value,verifyV=o('verify').value;
		if(!zeai.ifmob(mobV)){zeai.msg('请输入正确手机号',o('mob'));return false;}
		if(!zeai.ifint(verifyV)){zeai.msg('请输入手机验证码',o('verify'));return false;}
	}
	zeai.ajax({url:url+zeai.extname,js:1,form:WWW_ZEAI_CN_form},function (e){var rs=zeai.jsoneval(e);
		if (rs.flag==1){
			if(reg_kind==1)clearTimeout(cleandsj);
			zeai.msg(rs.msg);
			setTimeout(function(){zeai.openurl(rs.jumpurl);},1000);
		}else{
			zeai.msg(rs.msg,{time:4});
		}
	});
}
clause.onclick=function(){ZeaiM.div_left({obj:clausebox});}
<?php if ($TG_set['regkind'] == 2){?>
forgetpass_btn.onclick=forgetpass_btnFn;
function forgetpass_btnFn(){ZeaiM.div_up({obj:forgetpassbox,h:30});}
<?php }?>
</script>
<div id="blankpage"></div>
</body></html>
<?php
function chk_flag1Fn($SQL,$regkind2='') {
	global $db,$js,$_ZEAI,$_SESSION,$TG_set,$pwd,$jumpurl,$server_tg_openid,$ip,$loginkind;
	$row = $db->ROW(__TBL_TG_USER__,"id,pwd,flag,openid,buyflag",$SQL,'name');
	if ($row){
		if($pwd==$row['pwd'] || $TG_set['regkind'] == 1){
			setcookie("cook_tg_uid",$row['id'],time()+31536000,"/",$_ZEAI['CookDomain']);
			setcookie("cook_tg_pwd",$row['pwd'],time()+31536000,"/",$_ZEAI['CookDomain']);
		}
		//
		if($loginkind=='shop'){
			$flag = $row['buyflag'];
		}else{
			$flag = $row['flag'];
		}
		if($flag == 1){
			if ($TG_set['regkind'] == 2 && $row['pwd']!=$pwd){//用户名注册
				json_exit(array('flag'=>0,'msg'=>'当前帐号已注册<br>请检查密码是否正确<br>或更换其他账号'));
			}
			//为空自动更新openid
			if(is_weixin()){
				if(str_len($server_tg_openid)>20 && empty($row['openid'])){
					$row2 = $db->ROW(__TBL_TG_USER__,"id","openid='".$server_tg_openid."'");
					if (!$row2){
						$SQL2 = ",openid='$server_tg_openid'";
					}
				}
			}
			$db->query("UPDATE ".__TBL_TG_USER__." SET endtime=".ADDTIME.",endip='$ip',logincount=logincount+1".$SQL2." WHERE id=".$row['id']);
			unset($_SESSION["Zeai_cn__verify"]);
			unset($_SESSION["Zeai_cn__mob"]);
			//
			setcookie("cook_tg_uid",$row['id'],time()+31536000,"/",$_ZEAI['CookDomain']);
			setcookie("cook_tg_pwd",$row['pwd'],time()+31536000,"/",$_ZEAI['CookDomain']);
			$jumpurl = trimhtml(urldecode($jumpurl));
			if($loginkind=='shop'){
				$jumpurl=(!empty($jumpurl))?$jumpurl:'shop_my.php';
			}else{
				$jumpurl=(!empty($jumpurl))?$jumpurl:'tg_my.php';
			}
			//
			if($js==1){
				json_exit(array('flag'=>'logined','msg'=>'登录成功','jumpurl'=>$jumpurl));
			}else{
				header("Location: ".$jumpurl);exit;
			}
		}elseif($flag == -1){
			$msg='当前帐号已被锁定或注销';
			if($js==1){
				json_exit(array('flag'=>0,'msg'=>$msg));
			}else{
				callmsg($msg,'-1');
			}
		}elseif($flag == 0){
			$msg='当前帐号已经注册，请等待审核';
			if($js==1){
				json_exit(array('flag'=>0,'msg'=>'当前帐号已经注册，请等待帐号审核'));
			}else{
				callmsg($msg,HOST);
			}
		}elseif($flag == 2){
			if($loginkind=='shop'){
				$jumpurl=(!empty($jumpurl))?$jumpurl:'shop_my.php';
			}else{
				$jumpurl='tg_reg.php?submitok=flag2';
			}
			if($js==1){
				json_exit(array('flag'=>'logined','msg'=>'登录成功，请激活','jumpurl'=>$jumpurl));
			}else{
				header("Location: ".$jumpurl);exit;
			}
		}
	}
}


function chk_flag_tg_shop($row) {
	global $db,$js,$_ZEAI,$_SESSION,$TG_set,$pwd,$jumpurl,$server_tg_openid,$ip,$loginkind;
	if($loginkind=='shop'){
		$flag = $row['buyflag'];
	}else{
		$flag = $row['flag'];
	}
	if($flag == 1){
		//提交用户名注册
		if ($TG_set['regkind'] == 2 && $row['pwd']!=$pwd){
			json_exit(array('flag'=>0,'msg'=>'当前帐号已注册<br>请检查密码是否正确<br>或更换其他账号'));
		}
		//为空自动更新openid v8.2
		if(is_weixin()){
			if(str_len($server_tg_openid)>20 && empty($row['openid'])){
				$row2 = $db->ROW(__TBL_TG_USER__,"id","openid='".$server_tg_openid."'");
				if (!$row2){
					$SQL2 = ",openid='$server_tg_openid'";
				}
			}
		}
		$db->query("UPDATE ".__TBL_TG_USER__." SET endtime=".ADDTIME.",endip='$ip',logincount=logincount+1".$SQL2." WHERE id=".$row['id']);
		unset($_SESSION["Zeai_cn__verify"]);
		unset($_SESSION["Zeai_cn__mob"]);
		//
		setcookie("cook_tg_uid",$row['id'],time()+31536000,"/",$_ZEAI['CookDomain']);
		setcookie("cook_tg_pwd",$row['pwd'],time()+31536000,"/",$_ZEAI['CookDomain']);
		$jumpurl = trimhtml(urldecode($jumpurl));
		if($loginkind=='shop'){
			$jumpurl=(!empty($jumpurl))?$jumpurl:'shop_my.php';
		}else{
			$jumpurl=(!empty($jumpurl))?$jumpurl:'tg_my.php';
		}
		//
		if($js==1){
			json_exit(array('flag'=>'logined','msg'=>'登录成功','jumpurl'=>$jumpurl));
		}else{
			header("Location: ".$jumpurl);exit;
		}
	}elseif($flag == -1){
		$msg='当前帐号已被锁定或注销';
		if($js==1){
			json_exit(array('flag'=>0,'msg'=>$msg));
		}else{
			callmsg($msg,'-1');
		}
	}elseif($flag == 0){
		$msg='当前帐号已经注册，请等待审核';
		if($js==1){
			json_exit(array('flag'=>0,'msg'=>'当前帐号已经注册，请等待帐号审核'));
		}else{
			callmsg($msg,HOST);
		}
	}elseif($flag == 2){
		if($loginkind=='shop'){
			$jumpurl=(!empty($jumpurl))?$jumpurl:'shop_my.php';
		}else{
			$jumpurl='tg_reg.php?submitok=flag2';
		}
		if($js==1){
			json_exit(array('flag'=>'logined','msg'=>'登录成功，请激活','jumpurl'=>$jumpurl));
		}else{
			header("Location: ".$jumpurl);exit;
		}
	}
}
?>